﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using compshop.Infrastructure.CompShopDataService;
using compshop.Modules.ListOfWaybills.Presenter;

namespace compshop.Modules.ListOfWaybills.View
{
    /// <summary>
    /// Логика взаимодействия для WaybillListView.xaml
    /// </summary>
    public partial class WaybillListView : UserControl, IViewWaybillList
    {
        public WaybillListPresenter Presenter
        {
            get { return DataContext as WaybillListPresenter; }
            set { DataContext = value; }
        }

        public WaybillListView()
        {
            InitializeComponent();

        }

        public WaybillListView(WaybillListPresenter presenter)
            : this()
        {
            Presenter = presenter;
            Presenter.View = this;
            DataGridComboBoxColumn column = dgWaybillList.Columns[1] as DataGridComboBoxColumn;
            column.ItemsSource = presenter.DepartmentList;
            column = dgWaybillList.Columns[2] as DataGridComboBoxColumn;
            column.ItemsSource = presenter.DepartmentList;
            
            dgWaybillList.SelectionChanged += new SelectionChangedEventHandler(dgWaybillList_SelectionChanged);

        }

        void dgWaybillList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dgWaybillList.SelectedValue!=null)
            Presenter.WayBillSelectedPublisher((int)(decimal)dgWaybillList.SelectedValue);
        }
        
    }
}
